{% extends "explorer/base.html" %}
{% load explorer_tags i18n %}

{% block sql_explorer_content %}
<div class="container">
    <div class="row">
        <div id="query_area">
            <h2>{% trans "Playground" %}</h2>
            <p>
                {% blocktrans trimmed %}
                    The playground is for experimenting and writing ad-hoc queries. By default, nothing you do here will be saved.
                {% endblocktrans %}
            </p>
            <form role="form" action="{% url 'explorer_playground' %}" method="post" id="editor" class="playground-form form-horizontal">{% csrf_token %}
                {% if error %}
                    <div class="alert alert-danger db-error">{{ error|escape }}</div>
                {% endif %}
                {{ form.non_field_errors }}
                {% if form.connections|length > 1 and can_change %}
                    <div class="mb-3 form-floating">
                        {{ form.connection }}
                        <label for="id_connection" class="form-label">{% trans "Connection" %}</label>
                    </div>
                {% else %}
                    {# still need to submit the connection, just hide the UI element #}
                    <div class="hidden">
                      {{ form.connection }}
                    </div>
                {% endif %}
                <div class="row">
                    <div class="col">
                        <label for="id_sql" class="form-label">SQL</label>
                    </div>
                    <div class="col text-end">
                        {% if ql_id %}
                            <a href="{% url 'explorer_playground' %}?querylog_id={{ ql_id }}">
                                <i class="bi-link"></i>
                            </a>
                        {% endif %}
                    </div>
                </div>
                <div class="row">
                    <textarea class="form-control" cols="40" id="id_sql" name="sql" rows="20">{{ query.sql }}</textarea>
                </div>

                <div class="mt-3 text-center">
                    <div class="btn-group" role="group">
                        <button type="submit" id="refresh_play_button"
                                class="btn btn-primary">{% trans 'Refresh' %}</button>
                        <button type="submit" id="create_button"
                                class="btn btn-outline-primary">{% trans 'Save As New' %}</button>
                        {% export_buttons query %}

                        <button type="button" class="btn btn-outline-primary" id="show_schema_button">
                            {% trans "Show Schema" %}
                        </button>
                        <button type="button" class="btn btn-outline-primary" id="hide_schema_button"
                                style="display: none;">
                            {% trans "Hide Schema" %}
                        </button>
                        <button type="button" class="btn btn-outline-primary" id="format_button">
                            {% trans "Format" %}
                        </button>
                    </div>
                </div>
                <input type="hidden" value="{% trans 'Playground Query' %}" name="title" />
                {% if assistant_enabled %}
                    {% include 'explorer/assistant.html' %}
                {% endif %}
            </form>
        </div>
        <div id="schema" style="display: none;">
            <iframe src="about:blank" height="828px" frameBorder="0" id="schema_frame"></iframe>
        </div>
    </div>
</div>
{% include 'explorer/preview_pane.html' %}

{% endblock %}
